# -*- coding : utf_8 -*-
"""
=======================================
Time : 2025/4/13 19:59
Author : 田霄汉
Email : 522989570@qq.com
File : combat_class16.py
Project : pandas_demo
Function : 求总分和平均分
=======================================
"""
import pandas as pd
from config.setting import file_path

combat16_path = file_path['excel_path'] + '/combat16.xlsx'
Score_df = pd.read_excel(io=combat16_path,
                         skiprows=3,
                         usecols='C:G',
                         index_col='id')

row_score = Score_df[['Test01', 'Test02', 'Test03']]
# axis=1是从左到右，按行求平均值和求和
row_score_sum = row_score.sum(axis=1)
row_score_mean = row_score.mean(axis=1)
# row_score_sum是每个学生的总和
Score_df['Sum'] = row_score_sum
# row_score_mean是每个学生的平均值
Score_df['Mean'] = row_score_mean


col_score = Score_df[['Test01', 'Test02', 'Test03', 'Sum', 'Mean']]
# axis=0就是从上往下，按列求平均值
col_score_mean = col_score.mean(axis=0)
# clo_score_mean是每一列的平均值
col_score_mean['Full Name'] = 'Summary'
Score_df = Score_df.append(col_score_mean, ignore_index=True)
print(Score_df)
